package com.hexacta.hrs.sandbox.meetings.data;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.hexacta.hrs.sandbox.meetings.model.Activity;
import com.hexacta.hrs.sandbox.meetings.model.Meeting;
import com.hexacta.hrs.sandbox.meetings.model.Theme;

/**
 * Persiste la clase Activity.
 * @author ncortinez
 *
 */
public class ActivityDAO extends HibernateDaoSupport{
    public void saveOrUpdate(Activity actividad) {
        this.getHibernateTemplate().saveOrUpdate(actividad);
    }
    
    public void delete(Activity actividad) {
        this.getHibernateTemplate().delete(actividad);
    }
    
    public Activity findById(Long id) {
        Activity activity = (Activity) this.getHibernateTemplate().get(Activity.class, id);
        this.inicializar(activity);
        return activity;
    }
    
    private void inicializar(Activity activity){
    	// FIXME no queremos recorrer todas las colecciones para cargar los datos. y si levantamos en eager?
		for(Meeting m : activity.getMyTheme().getMeeting().getMentor().getMeetings()){
	    	for (Theme t : m.getThemes()) {
				for(Activity a : t.getActivities()){
					a.getId();
				}
			}
		}
	}
}
